package com.taokatao.cardmee.business.cardcode;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.TextView;

import com.taokatao.cardmee.App;
import com.taokatao.cardmee.R;
import com.taokatao.cardmee.Utils;
import com.taokatao.cardmee.WebActivity;
import com.taokatao.cardmee.api.security.ServiceUrlProvider;
import com.taokatao.cardmee.db.CardDao;
import com.taokatao.cardmee.db.model.Card;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CardCodeOtherLayout extends ICardDetailInfoLayout implements View.OnClickListener {

    @BindView(R.id.t_other) TextView tOther;
    @BindView(R.id.t_username) TextView tUsername;
    @BindView(R.id.t_user_tel) TextView tUserTel;
    @BindView(R.id.t_comment) TextView tComment;

    Card c;

    public CardCodeOtherLayout(Context context) {
        this(context, null);
    }

    public CardCodeOtherLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        ButterKnife.bind(LayoutInflater.from(context).inflate(R.layout.layout_card_code_other, this));

        tComment.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG | Paint.UNDERLINE_TEXT_FLAG);
    }

    @Override
    void prepareData(final Card card) {
        if (card == null) return;
        c = card;

        boolean shareEnable = (card.getShareType() != null && 9 == card.getShareType());
        tComment.setVisibility(shareEnable ? View.VISIBLE : View.GONE);

        tUsername.setText("持卡人姓名：" + (TextUtils.isEmpty(c.getCardUser()) ? "" : c.getCardUser()));
        tUserTel.setText("持卡人电话：" + (TextUtils.isEmpty(c.getCardTel()) ? "" : c.getCardTel()));
        tOther.setText("其它信息：" +
                (TextUtils.isEmpty(c.getRemark()) ? "" : c.getRemark().replaceAll("\\\\n", "\n")));
    }

    @Override
    @OnClick({R.id.t_comment})
    public void onClick(View v) {
        if (v == tComment) {
            Utils.onMobEvent(getContext(), "clickViewCommentOfMore");
            Intent intent = new Intent(getContext(), WebActivity.class);
            intent.putExtra("extra_url", ServiceUrlProvider.obtainCommentUrl(c.getMCardId()));
            getContext().startActivity(intent);
        }
    }
}
